package com.yufubao.api.controller.management.product;

import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.pojo.applet.product.SupplierProductCategoryEntity;
import com.yufubao.service.service.applet.product.SupplierProductCategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author 张一恒
 * @version 1.0
 * @description: 商品三级分类
 * @date 2024/9/18 18:42
 */
@RestController
@RequestMapping("/applet/management/product/category")
public class CategoryController {

    @Autowired
    private SupplierProductCategoryService supplierProductCategoryService;

    /**
     * applet产品分类树化
     */
    @SystemLog(info = "applet产品分类树化")
    @RequestMapping(value = "/listTree",method = RequestMethod.GET)
    @ApiOperation(value = "applet产品分类树化")
    public ResponseResult listTree(){
        return supplierProductCategoryService.listTree();
    }


    /**
     * 修改节点顺序
     */
    @RequestMapping(value = "/update/sort",method = RequestMethod.POST)
    @ApiOperation(value = "修改节点顺序")
    @SystemLog(info = "修改节点顺序")
    public ResponseResult updateSort(@RequestBody SupplierProductCategoryEntity[] category){
        supplierProductCategoryService.updateBatchById(Arrays.asList(category));

        return ResponseResult.ok();
    }

    /**
     * 信息
     */
    @RequestMapping(value = "/info/{catId}",method = RequestMethod.GET)
    @ApiOperation(value = "信息")
    @SystemLog(info = "信息")
    public ResponseResult info(@PathVariable("catId") Long catId){
        SupplierProductCategoryEntity category = supplierProductCategoryService.getById(catId);

        return ResponseResult.okResultPage("category", category);
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "修改")
    @SystemLog(info = "修改")
    public ResponseResult update(@RequestBody SupplierProductCategoryEntity category){
        supplierProductCategoryService.updateByIdAndintermediateTable(category);

        return ResponseResult.ok();
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存")
    @SystemLog(info = "保存")
    public ResponseResult save(@RequestBody SupplierProductCategoryEntity category){
        supplierProductCategoryService.save(category);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "删除")
    @SystemLog(info = "删除")
    public ResponseResult delete(@RequestBody Long[] catIds){
//		categoryService.removeByIds(Arrays.asList(catIds));
        supplierProductCategoryService.removeMenuByIds(Arrays.asList(catIds));

        return ResponseResult.ok();
    }
}
